home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevmr2n.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.1 KB  |  181 lines

  1. /* Copyright (C) 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevmr2n.c,v 1.2 2000/09/19 19:00:14 lpd Exp $ */
  20. /* RasterOp implementation for 2- and 4-bit memory devices */
  21. #include "memory_.h"
  22. #include "gx.h"
  23. #include "gsbittab.h"
  24. #include "gserrors.h"
  25. #include "gsropt.h"
  26. #include "gxcindex.h"
  27. #include "gxdcolor.h"
  28. #include "gxdevice.h"
  29. #include "gxdevmem.h"
  30. #include "gxdevrop.h"
  31. #include "gdevmem.h"
  32. #include "gdevmrop.h"
  33.  
  34. /* Calculate the X offset for a given Y value, */
  35. /* taking shift into account if necessary. */
  36. #define x_offset(px, ty, textures)\
  37.   ((textures)->shift == 0 ? (px) :\
  38.    (px) + (ty) / (textures)->rep_height * (textures)->rep_shift)
  39.  
  40. /* ---------------- Fake RasterOp for 2- and 4-bit devices ---------------- */
  41.  
  42. /*
  43.  * Define patched versions of the driver procedures that may be called
  44.  * by mem_mono_strip_copy_rop (see below).  Currently we just punt to
  45.  * the slow, general case; we could do a lot better.
  46.  */
  47. private int
  48. mem_gray_rop_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
  49.                 gx_color_index color)
  50. {
  51.     return -1;
  52. }
  53. private int
  54. mem_gray_rop_copy_mono(gx_device * dev, const byte * data,
  55.                int dx, int raster, gx_bitmap_id id,
  56.                int x, int y, int w, int h,
  57.                gx_color_index zero, gx_color_index one)
  58. {
  59.     return -1;
  60. }
  61. private int
  62. mem_gray_rop_strip_tile_rectangle(gx_device * dev,
  63.                   const gx_strip_bitmap * tiles,
  64.                   int x, int y, int w, int h,
  65.                   gx_color_index color0, gx_color_index color1,
  66.                   int px, int py)
  67. {
  68.     return -1;
  69. }
  70.  
  71. int
  72. mem_gray_strip_copy_rop(gx_device * dev,
  73.          const byte * sdata, int sourcex, uint sraster, gx_bitmap_id id,
  74.             const gx_color_index * scolors,
  75.        const gx_strip_bitmap * textures, const gx_color_index * tcolors,
  76.             int x, int y, int width, int height,
  77.             int phase_x, int phase_y, gs_logical_operation_t lop)
  78. {
  79.     gx_color_index scolors2[2];
  80.     const gx_color_index *real_scolors = scolors;
  81.     gx_color_index tcolors2[2];
  82.     const gx_color_index *real_tcolors = tcolors;
  83.     gx_strip_bitmap texture2;
  84.     const gx_strip_bitmap *real_texture = textures;
  85.     long tdata;
  86.     int depth = dev->color_info.depth;
  87.     int log2_depth = depth >> 1;    /* works for 2, 4 */
  88.     gx_color_index max_pixel = (1 << depth) - 1;
  89.     int code;
  90.  
  91. #ifdef DEBUG
  92.     if (gs_debug_c('b'))
  93.     trace_copy_rop("mem_gray_strip_copy_rop",
  94.                dev, sdata, sourcex, sraster,
  95.                id, scolors, textures, tcolors,
  96.                x, y, width, height, phase_x, phase_y, lop);
  97. #endif
  98.     if (gx_device_has_color(dev) ||
  99.     (lop & (lop_S_transparent | lop_T_transparent)) ||
  100.     (scolors &&        /* must be (0,0) or (max,max) */
  101.      ((scolors[0] | scolors[1]) != 0) &&
  102.      ((scolors[0] & scolors[1]) != max_pixel)) ||
  103.     (tcolors && (tcolors[0] != tcolors[1]))
  104.     ) {
  105.     /* We can't fake it: do it the slow, painful way. */
  106.     return mem_default_strip_copy_rop(dev, sdata, sourcex, sraster, id,
  107.                       scolors, textures, tcolors,
  108.                       x, y, width, height,
  109.                       phase_x, phase_y, lop);
  110.     }
  111.     if (scolors) {        /* Must be a solid color: see above. */
  112.     scolors2[0] = scolors2[1] = scolors[0] & 1;
  113.     real_scolors = scolors2;
  114.     }
  115.     if (textures) {
  116.     texture2 = *textures;
  117.     texture2.size.x <<= log2_depth;
  118.     texture2.rep_width <<= log2_depth;
  119.     texture2.shift <<= log2_depth;
  120.     texture2.rep_shift <<= log2_depth;
  121.     real_texture = &texture2;
  122.     }
  123.     if (tcolors) {
  124.     /* For polybit textures with colors other than */
  125.     /* all 0s or all 1s, fabricate the data. */
  126.     if (tcolors[0] != 0 && tcolors[0] != max_pixel) {
  127.         real_tcolors = 0;
  128.         *(byte *) & tdata = (byte) tcolors[0] << (8 - depth);
  129.         texture2.data = (byte *) & tdata;
  130.         texture2.raster = align_bitmap_mod;
  131.         texture2.size.x = texture2.rep_width = depth;
  132.         texture2.size.y = texture2.rep_height = 1;
  133.         texture2.id = gx_no_bitmap_id;
  134.         texture2.shift = texture2.rep_shift = 0;
  135.         real_texture = &texture2;
  136.     } else {
  137.         tcolors2[0] = tcolors2[1] = tcolors[0] & 1;
  138.         real_tcolors = tcolors2;
  139.     }
  140.     }
  141.     /*
  142.      * mem_mono_strip_copy_rop may call fill_rectangle, copy_mono, or
  143.      * strip_tile_rectangle for special cases.  Patch those procedures
  144.      * temporarily so they will either do the right thing or return
  145.      * an error.
  146.      */
  147.     {
  148.     dev_proc_fill_rectangle((*fill_rectangle)) =
  149.         dev_proc(dev, fill_rectangle);
  150.     dev_proc_copy_mono((*copy_mono)) =
  151.         dev_proc(dev, copy_mono);
  152.     dev_proc_strip_tile_rectangle((*strip_tile_rectangle)) =
  153.         dev_proc(dev, strip_tile_rectangle);
  154.  
  155.     set_dev_proc(dev, fill_rectangle, mem_gray_rop_fill_rectangle);
  156.     set_dev_proc(dev, copy_mono, mem_gray_rop_copy_mono);
  157.     set_dev_proc(dev, strip_tile_rectangle,
  158.              mem_gray_rop_strip_tile_rectangle);
  159.     dev->width <<= log2_depth;
  160.     code = mem_mono_strip_copy_rop(dev, sdata,
  161.                        (real_scolors == NULL ?
  162.                     sourcex << log2_depth : sourcex),
  163.                        sraster, id, real_scolors,
  164.                        real_texture, real_tcolors,
  165.                        x << log2_depth, y,
  166.                        width << log2_depth, height,
  167.                        phase_x << log2_depth, phase_y, lop);
  168.     set_dev_proc(dev, fill_rectangle, fill_rectangle);
  169.     set_dev_proc(dev, copy_mono, copy_mono);
  170.     set_dev_proc(dev, strip_tile_rectangle, strip_tile_rectangle);
  171.     dev->width >>= log2_depth;
  172.     }
  173.     /* If we punted, use the general procedure. */
  174.     if (code < 0)
  175.     return mem_default_strip_copy_rop(dev, sdata, sourcex, sraster, id,
  176.                       scolors, textures, tcolors,
  177.                       x, y, width, height,
  178.                       phase_x, phase_y, lop);
  179.     return code;
  180. }
  181.